<!--栏目管理列表-->
<style lang="less">
  @import 'cms_content.less';
</style>

<template>
  <div id="cms_content">
    <Row>
      <Col span="24">
        <Card style="margin-bottom: 10px">
          <Form inline ref="searchConf" :model="searchConf" class="cms_contentTable" @submit.native.prevent>
            <FormItem prop="classid">
              <Select @on-change="search" v-model="searchConf.classid" clearable  filterable placeholder="请选择栏目" style="width:150px">
                <template v-for="item in classList">
                  <Option :value="item.id" :disabled="item.islast === 1 ? false : true">{{item.showName}}</Option>
                </template>
              </Select>
            </FormItem>
            <FormItem prop="hide">
              <Select @on-change="search" v-model="searchConf.hide" clearable placeholder="请选择状态" style="width:150px">
                <Option :value="0">正常</Option>
                <Option :value="1">归档</Option>
              </Select>
            </FormItem>
            <FormItem prop="title">
              <Input v-model="searchConf.title" clearable placeholder="请输入标题..." style="width: 250px" @on-enter="search"></Input>
            </FormItem>
            <FormItem>
              <Button type="primary" @click="search">查询</Button>
            </FormItem>
            <FormItem>
              <Button @click="schReset('searchConf')">重置</Button>
            </FormItem>
            <FormItem>
              <Button type="primary" @click="alertAdd" icon="md-add">新增</Button>
            </FormItem>
          </Form>
        </Card>
      </Col>
      <Col span="24">
        <Card>
          <div>
            <Table :loading="tableLoading" :columns="columnsList" :data="tableData" border disabled-hover>
              <template slot-scope="{ row, index }" slot="handle">
                <Button type="primary" style="margin-right: 5px" @click="edit(row.id, index)">编辑</Button>
                <Poptip
                  confirm
                  title="您确定要删除这条数据吗?"
                  :transfer='true'
                  @on-ok="del(row.id, index)">
                  <Button type="error">删除</Button>
                </Poptip>
              </template>
            </Table>
          </div>
          <div class="margin-top-15" style="text-align: center;margin-top: 20px">
            <Page :total="tableShow.listCount" :current="tableShow.currentPage"
                  :page-size="tableShow.pageSize" @on-change="changePage"
                  @on-page-size-change="changeSize" show-elevator show-sizer show-total></Page>
          </div>
        </Card>
      </Col>
    </Row>
    <!--编辑或新增-->
    <Modal v-model="modalSetting.show" :z-index="399"  :mask-closable="false" width="1000" :styles="{top: '0px',paddingTop: '30px'}" draggable class="cms_contentModel" :scrollable="true" @on-visible-change="doCancel">
      <p slot="header" style="color:#fff;">
        <Icon type="md-information-circle"></Icon>
        <span>{{formItem.id ? '编辑' : '新增'}}内容</span>
      </p>
      <Form ref="myForm" :model="formItem" :rules="ruleValidate" :label-width="80">
        <Divider orientation="left" class="divider">基础信息</Divider>
        <FormItem label="栏目名称" prop="classid">
          <Select v-model="formItem.classid" clearable filterable style="width: 300px">
            <Option v-for="item in classList" :value="item.id" :key="item.id" :disabled="item.islast === 1 ? false : true">{{ item.showName }}</Option>
          </Select>
          <span style="color: #FD6732; margin-left: 15px">只有终极栏目才可以增加内容</span>
        </FormItem>
        <FormItem label="标题" prop="title">
          <Input v-model="formItem.title" placeholder="请输入标题"></Input>
        </FormItem>
        <FormItem label="关键字" prop="keyboard">
          <Input v-model="formItem.keyboard" placeholder="请输入标题"></Input>
        </FormItem>
        <FormItem label="缩略图" prop="headimg" class="imgUpload">
          <div class="demo-upload-list" v-if="formItem.headimg">
            <img :src=" imgSrc + formItem.headimg" style="max-height: 150px" @click="imgPreview">
            <div class="demo-upload-list-cover">
              <Icon type="ios-trash-outline" @click.native="handleImgRemove()"></Icon>
            </div>
          </div>
          <input v-if="formItem.headimg" v-model="formItem.headimg" type="hidden" name="image">
          <Upload type="drag"
                  :action="uploadUrl"
                  :headers="uploadHeader"
                  v-if="!formItem.headimg"
                  :format="['jpg','jpeg','png','gif','bmp']"
                  :max-size="5120"
                  name="upload"
                  :on-success="handleImgSuccess"
                  :on-format-error="handleImgFormatError"
                  :on-exceeded-size="handleImgMaxSize"
                  style="display: inline-block;width:200px;">
            <div style="width: 200px;color: #2aa955;padding-top: 10px;">
              <Icon type="ios-cloud-upload" size="28"></Icon>
              <p>支持拖拽上传 jpg jpeg png <br/>建议640*426 / 500*200</p>
            </div>
          </Upload>
          <Button type="dashed" style="color: #DF8600;width: 200px" @click="showFilestList">图片空间列表</Button>
        </FormItem>
        <FormItem label="简介" prop="easytitle">
          <Input v-model="formItem.easytitle" type="textarea" :rows="3" placeholder="请输入栏目简介"></Input>
        </FormItem>
        <FormItem label="内容正文" prop="content" class="requiredItem">
          <ckEditor ref="ckEditor" v-model="formItem.content" class="contentEditor"></ckEditor>
        </FormItem>
        <FormItem label="发布时间" prop="newtime" class="requiredItem">
          <DatePicker v-model="formItem.newtime" type="datetime" placeholder="请选择发布时间" style="width: 250px"></DatePicker>
          <Button type="dashed" style="color: #DF8600;width: 100px;margin-left: 10px" @click="todyTime">当前时间</Button>
        </FormItem>
        <div class="operating tags">
          <Divider orientation="left" class="divider">TAG标签</Divider>
          <FormItem label="TAG标签" prop="tags">
            <Select v-model="tagName" filterable multiple title="TAG标签">
              <Option v-for="item in tagName" :value="item" :key="item">{{ item }}</Option>
            </Select>
            <Button type="dashed" style="color: #DF8600;width: 100px;margin-left: 10px" @click="showTagstList">选择</Button>
          </FormItem>
        </div>

        <div class="operating">
          <Divider orientation="left" class="divider">相关信息</Divider>
          <div class="formItem">
            <FormItem label="作者" prop="writer">
              <Input v-model="formItem.writer" placeholder="作者 | 非必填"></Input>
            </FormItem>
            <FormItem label="来源" prop="befrom">
              <Input v-model="formItem.befrom" placeholder="来源 | 非必填"></Input>
            </FormItem>

            <FormItem label="阅读数" prop="onclick">
              <InputNumber :min="0" v-model="formItem.onclick" title="阅读数 | 非必填" placeholder="阅读数 | 非必填" style="width: 220px"></InputNumber>
              <!--<Input v-model="formItem.onclick" placeholder="阅读数 | 非必填"></Input>-->
            </FormItem>
            <FormItem label="点赞数" prop="like">
              <InputNumber :min="0" v-model="formItem.likenum" title="点赞数 | 非必填" placeholder="点赞数 | 非必填" style="width: 220px"></InputNumber>
              <!--<Input v-model="formItem.like" placeholder="点赞数 | 非必填"></Input>-->
            </FormItem>
            <FormItem label="评论数" prop="discuss">
              <InputNumber :min="0" v-model="formItem.plnum" title="评论数 | 非必填" placeholder="评论数 | 非必填" style="width: 220px"></InputNumber>
              <!--<Input v-model="formItem.discuss" placeholder="评论数 | 非必填"></Input>-->
            </FormItem>
          </div>
        </div>

        <div class="operating">
          <Divider orientation="left" class="divider">状态</Divider>
          <div class="formItem">
            <FormItem label="头条等级" prop="isfirst">
              <Select v-model="formItem.isfirst">
                <Option v-for="item in isfirstData" :value="item.vlaue" :key="item.vlaue">{{ item.label }}头条</Option>
              </Select>
            </FormItem>
            <FormItem label="推荐等级" prop="isgood">
              <Select v-model="formItem.isgood">
                <Option v-for="item in isgoodData" :value="item.vlaue" :key="item.vlaue">{{ item.label }}推荐</Option>
              </Select>
            </FormItem>
            <FormItem label="置顶等级" prop="istop">
              <Select v-model="formItem.istop">
                <Option v-for="item in istopData" :value="item.vlaue" :key="item.vlaue">{{ item.label }}置顶</Option>
              </Select>
            </FormItem>
          </div>
        </div>

        <Spin fix v-if="editLoading">
          <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
          <div>Loading</div>
        </Spin>
      </Form>

      <div slot="footer">
        <Button type="text" @click="cancel" style="margin-right: 8px">取消</Button>
        <Button type="primary" @click="submit('myForm')" :loading="modalSetting.loading">确定</Button>
      </div>
    </Modal>
    <!--图片预览model-->
    <Modal v-model="imgModel" :footer-hide="true" class-name="imgPreview">
      <p slot="header" style="text-align: left">
        <span>图片预览</span>
      </p>
      <div style="text-align: center">
        <img :src="modelImg" width="100%">
      </div>
    </Modal>


    <!--图片空间列表model-->
    <filestList ref="filestList" @childImgUrl="childImgUrl"></filestList>
    <!--tag标签列表model-->
    <tagstList ref="tagstList" @childTag="childTag"></tagstList>
  </div>
</template>

<script>
  import { CmsColumnIndex } from '@/api/cms/menu'
  import { CmsContentListIndex, CmsContentListAdd, CmsContentListEdit, CmsContentListDetail, CmsContentListDel, CmsContentListChangeStatus, CmsContentListArchive} from '@/api/cms/content'


  // edit
  import ckEditor from "@/components/editor/ckEditor";
  import filestList from '@/components/cms/cms_fileslist'
  import tagstList from '@/components/cms/cms_tagslist'
  let userInfo
  export default {
    name: 'cms_content',
    components: {
        ckEditor, filestList, tagstList
    },
    data () {
      return {
        imgSrc: '', // 图片显示地址
        uploadUrl: '', // 图片上传接口地址
        uploadHeader: {},
        status: '是',
        columnsList: [
          {
            title: 'ID',
            type: 'id',
            sortable: true,
            width: 70,
            align: 'center',
            render: (h, params) => {
              return h('div', [
                h('span', {
                }, params.row.id)
              ])
            }
          },
          {
            title: '栏目',
            key: 'classid',
            width: 100,
            align: 'center',
            render: (h, params) => {
              return h('div', [
                h('span', {
                }, this.menuType(params.row.classid))
              ])
            }
          },
          {
            title: '标题',
            align: 'left',
            key: 'title',
            // width: 300,
            render: (h, params) => {
              return h('div', [
                h('span', {
                }, this.isNull(params.row.title))
              ])
            }
          },
          {
            title: '缩略图',
            align: 'center',
            key: 'easytitle',
            // width: 140,
            render: (h, params) => {
              if (params.row.headimg)
                return h('div', [
                  h('img', {
                    style: {
                      height: "80px",
                      width: "120px",
                      verticalAlign: "middle",
                      cursor: 'pointer',
                      margin: '5px auto'
                    },
                    attrs: {
                      src: this.imgSrc + params.row.headimg
                    },
                    on: {
                      'click': () => {
                        if (params.row.headimg) {
                          this.modelImg = this.imgSrc + params.row.headimg
                          this.imgModel = true
                        }
                      }
                    }
                  },)
                ])
              else
              return h('div', [
                h('span', {
                  style: {
                    height: "40px"
                  },
                }, '暂无')
              ])
            }
          },
          {
            title: '简介',
            align: 'left',
            key: 'easytitle',
            render: (h, params) => {
              return h('div', [
                h('span', {
                }, this.isNull(params.row.easytitle))
              ])
            }
          },
          {
            title: '作者',
            align: 'left',
            key: 'writer',
            width: 80,
            render: (h, params) => {
              return h('div', [
                h('span', {
                }, this.isNull(params.row.writer))
              ])
            }
          },
          {
            title: '来源',
            align: 'center',
            key: 'befrom',
            width: 80,
            render: (h, params) => {
              return h('div', [
                h('span', {
                }, this.isNull(params.row.befrom))
              ])
            }
          },
          {
            title: '点击数',
            align: 'center',
            sortable: true,
            width: 100,
            key: 'onclick',
            render: (h, params) => {
              return h('div', [
                h('span', {
                  style: {
                    color: '#28A753'
                  }
                }, this.isNull(params.row.onclick))
              ])
            }
          },
          {
            title: '点赞数',
            align: 'center',
            sortable: true,
            width: 100,
            key: 'likenum',
            render: (h, params) => {
              return h('div', [
                h('span', {
                  style: {
                    color: '#28A753'
                  }
                }, this.isNull(params.row.likenum))
              ])
            }
          },
          {
            title: '发布时间',
            align: 'center',
            key: 'newtime',
            sortable: true,
            width: 120,
            render: (h, params) => {
              return h('div', [
                h('span', {
                  /* style: {
                     color: '#FD6732'
                   }*/
                }, this.isNull(params.row.newtime))
              ])
            }
          },
          {
            title: '状态',
            align: 'center',
            key: 'hide',
            width: 100
          },
          {
            title: '操作',
            align: 'center',
            key: 'handle',
            width: 170,
            slot: 'handle'
          }
        ],
        tableLoading: false,
        tableData: [],
        tableShow: {
          currentPage: 1,
          pageSize: 10,
          listCount: 0
        },
        searchConf: {
          classid: '',
          title: '',
          hide: ''
        },
        modalSetting: {
          show: false,
          loading: false,
          index: 0
        },
        newtime: '', // 临时时间显示
        editForeItem: [],
        tagList: [],
        tagName: [], // 标签名称数组 单纯用于显示
        tagIds: [], // 标签id数组
        formItem: {
          id: 0,
          classid: '',
          title: '', // 标题
          keyboard: '', // 关键字
          headimg: '', // 标题图片
          headimgid: '', // 标题缩略图ID
          headimgidBefore: '', // 编辑之前的缩略图Id 用于后台判断是否修改缩略图
          easytitle: '', // 简介
          content: '', // 正文内容
          newtime: '', // 发布时间
          writer: '曾小晖', // 作者
          befrom: '原创', // 来源
          // tagids: '', // tagids
          tagnameBefore: '', // 编辑之前的tagname 用于后台判断是否修改tag
          tagname: '', // tagnames
          onclick: 0, // 点击数
          likenum: 0, // 点赞数
          plnum: 0, // 评论数
          userid: '', // 用户id
          username: '', // 用户名称
          updatetime: '', // 最后更新时间
          isfirst: '', // 头条等级 1-9
          istop: '', // 置顶等级 1-9
          isgood: '', // 推荐等级 1-9
          hide: 0 // 是否审核 0为审核
        },
        classList: [], // 栏目集合
        // 头条等级
        isfirstData: [
          {vlaue: 1, label: '一级'},
          {vlaue: 2, label: '二级'},
          {vlaue: 3, label: '三级'},
          {vlaue: 4, label: '四级'},
          {vlaue: 5, label: '五级'},
          {vlaue: 6, label: '六级'},
          {vlaue: 7, label: '七级'},
          {vlaue: 8, label: '八级'},
          {vlaue: 9, label: '九级'}
        ],
        // 置顶等级
        istopData: [
          {vlaue: 1, label: '一级'},
          {vlaue: 2, label: '二级'},
          {vlaue: 3, label: '三级'},
          {vlaue: 4, label: '四级'},
          {vlaue: 5, label: '五级'},
          {vlaue: 6, label: '六级'},
          {vlaue: 7, label: '七级'},
          {vlaue: 8, label: '八级'},
          {vlaue: 9, label: '九级'}
        ],
        // 推荐等级
        isgoodData: [
          {vlaue: 1, label: '一级'},
          {vlaue: 2, label: '二级'},
          {vlaue: 3, label: '三级'},
          {vlaue: 4, label: '四级'},
          {vlaue: 5, label: '五级'},
          {vlaue: 6, label: '六级'},
          {vlaue: 7, label: '七级'},
          {vlaue: 8, label: '八级'},
          {vlaue: 9, label: '九级'}
        ],
        // 表单校验
        ruleValidate: {
          classid: [
            { required: true, type: 'number', message: '请选择栏目', trigger: 'change' }
          ],
          title: [
            { required: true, message: '请输入标题', trigger: 'blur' }
          ],
          easytitle: [
            { required: true, message: '请输入简介', trigger: 'blur' },
            { type: 'string', min: 3, message: '简介不少于3个字', trigger: 'blur' }
          ]
        },
        imgModel: false, // 图片预览model
        modelImg: '', // 图片src
        editLoading: false // 编辑model login
      }
    },
    created () {
      this.imgSrc = this.$imgSrc
      this.init()
      this.menuList()
      this.getList()
      this.todyTime()
    },
    mounted () {

    },
    methods: {
      init () {
        let vm = this
        userInfo = JSON.parse(sessionStorage.getItem('userData'))
        vm.formItem.username = userInfo.username
        vm.formItem.userid = userInfo.id
        // 文件上传地址
        vm.uploadUrl = this.$baseUrl + 'CmsContentList/upload'
        vm.uploadHeader = {
            'ApiAuth': userInfo.apiAuth,
            userid: userInfo.id,
            username: userInfo.username,
            isheadimg: 1
        }

        this.columnsList.forEach(item => {
          if (item.key === 'hide') {
            item.render = (h, param) => {
              let currentRowData = vm.tableData[param.index]
              return h('i-switch', {
                attrs: {
                  size: 'large'
                },
                props: {
                  'true-value': 0,
                  'false-value': 1,
                  value: currentRowData.hide
                },
                on: {
                  'on-change': function (status) {
                    CmsContentListChangeStatus({
                      status: status,
                      id: currentRowData.id
                    }).then(function (response) {
                      let res = response.data
                      if (res.code === 1) {
                        vm.$Message.success(res.msg)
                      } else {
                        vm.$Message.error(res.msg)
                        vm.getList()
                      }
                      vm.cancel()
                    })
                  }
                }
              }, [
                h('span', {
                  slot: 'open'
                }, '正常'),
                h('span', {
                  slot: 'close'
                }, '归档')
              ])
            }
          }
        })
      },
      alertAdd () {
          this.$refs.ckEditor.showEdit(false) // 关闭ckEdit
          this.$nextTick(()=>{
              this.$refs.ckEditor.showEdit(true)
          })
        this.modalSetting.show = true
        // 平滑滚动到顶部
        let s = document.getElementsByClassName('ivu-modal-body')
        let timer = setInterval(function(){
          let scrollTop = s[0].scrollTop;
          let ispeed = Math.floor(-scrollTop/6);
          if(scrollTop === 0){
            clearInterval(timer);
          }
          s[0].scrollTop = scrollTop+ispeed;
        },30)
      },
      // 编辑
      edit (id, index) {
        let vm = this
        vm.editLoading = true
        vm.modalSetting.show = true
        let s = document.getElementsByClassName('ivu-modal-body')
        let timer = setInterval(function(){
          let scrollTop = s[0].scrollTop;
          let ispeed = Math.floor(-scrollTop/6);
          if(scrollTop === 0){
            clearInterval(timer);
          }
          s[0].scrollTop = scrollTop+ispeed;
        },30)
          this.$refs.ckEditor.showEdit(false) // 关闭ckEdit
        // 详情
        CmsContentListDetail({'id': id}).then(response => {
          vm.modalSetting.index = index
          let res = response.data
          if (res.code === 1) {
            vm.editLoading = false
            vm.formItem = res.data

            vm.formItem.username = userInfo.username
            vm.formItem.userid = userInfo.id

            if (vm.formItem.tagname !== '') {
              vm.tagName = JSON.parse(vm.formItem.tagname)
            }
            vm.newtime = res.data.newtime
            // 获取缩略图图片Id 用于检测是否更改缩略图
            vm.formItem.headimgidBefore = res.data.headimgid
            // 获取tagname 用于后台判断是否修改tag
            vm.formItem.tagnameBefore = res.data.tagname
              this.$refs.ckEditor.showEdit(true)
          } else {
            vm.$Message.error(res.msg)
            vm.editLoading = false
          }
        })
      },
      // 查询
      search () {
        this.tableShow.currentPage = 1
        this.getList()
      },
      // 重置
      schReset (name) {
        this.$refs[name].resetFields();
        this.getList()
      },
      // 分页
      changePage (page) {
        this.tableShow.currentPage = page
        this.getList()
      },
      changeSize (size) {
        this.tableShow.pageSize = size
        this.getList()
      },
      // 删除
      del (id, index) {
        let vm = this
        CmsContentListDel({'id': id}).then(response => {
          if (response.data.code === 1) {
            vm.tableData.splice(index, 1)
            vm.$Message.success(response.data.msg)
          } else {
            vm.$Message.warning(response.data.msg)
          }
        })
      },
      menuList () {
        // 获取所有栏目列表
        CmsColumnIndex ().then( res => {
          if (res.data.code === 1) {
            this.classList = res.data.data.list
            localStorage.setItem('cmsMenu',JSON.stringify(this.classList))
          } else {
            this.$Message.warning(response.data.msg)
          }
        }).catch(err => {
          console.log(err)
        })
      },
      statusType (e) {
        switch (e) {
          case '是':
            this.formItem.hide = 0
            break
          default:
            this.formItem.hide = 1
        }
      },
      // 获取当前时间 YYYY-MM-DD HH:mm:ss
      todyTime () {
        let moment = require('moment')
        let time = moment().format('YYYY-MM-DD HH:mm:ss')
        this.formItem.newtime = time
        // console.log(this.formItem.newtime);
      },
      // 新增或编辑
      submit (name) {
        let self = this
        this.$refs[name].validate((valid) => {
          if (valid) {
            if (self.formItem.content === '') {
              self.$Message.warning('请输入正文内容')
              return
            } else if (self.formItem.newtime === '') {
              self.$Message.warning('请选择发布时间')
              return
            }
            // tag转字符串
            this.formItem.tagname = JSON.stringify(this.tagName)
            // this.formItem.tagids = JSON.stringify(this.tagIds)
            // console.log(this.formItem.tags);
            // 时间格式化
            let moment = require('moment')
            self.formItem.newtime = moment(this.formItem.newtime).format('YYYY-MM-DD HH:mm:ss')
            self.modalSetting.loading = true;
            // 过滤xss攻击
            // let xss = require('xss')
            // self.formItem.content = xss(self.formItem.content)
            // 新增
            if (this.formItem.id === 0) {
              CmsContentListAdd(this.formItem).then(response => {
                if (response.data.code === 1) {
                  self.$Message.success(response.data.msg)
                  self.getList()
                  self.cancel()
                  self.modalSetting.loading = false;
                } else {
                  self.$Message.warning(response.data.msg)
                }
              }).catch(err => {
                self.modalSetting.loading = false;
                console.log(err)
              })
            } else {
              // 编辑
              CmsContentListEdit(this.formItem).then(response => {
                if (response.data.code === 1) {
                  self.modalSetting.loading = false;
                  self.$Message.success(response.data.msg)
                  self.getList()
                  self.cancel()
                } else {
                  self.$Message.warning(response.data.msg)
                }
              })
            }
          } else {
            self.modalSetting.loading = false;
            self.$Message.warning('信息未填写完整')
          }
        })
      },
      cancel () {
        this.modalSetting.show = false
        this.$refs['myForm'].resetFields()
        this.$refs.ckEditor.showEdit(false)
      },
      // model 状态改变时触发(关闭或显示)
      doCancel (data) {
        // console.log(data);
        // if (!data) {
        //
        // }
        this.formItem.id = 0
        this.formItem.headimgid = ''
        this.formItem.headimgidBefore = ''
        this.$refs['myForm'].resetFields()
        this.modalSetting.loading = false
        this.modalSetting.index = 0
        this.formItem.tagname = []
        this.formItem.tagids = []
      },
      // 获取列表
      getList () {
        let vm = this
        vm.tableLoading = true
        CmsContentListIndex({
            page: vm.tableShow.currentPage,
            size: vm.tableShow.pageSize,
            classid: vm.searchConf.classid,
            title: vm.searchConf.title,
            hide: vm.searchConf.hide
          }
        ).then(response => {
          let res = response.data
          vm.tableLoading = false
          if (res.code === 1) {
            vm.tableData = res.data.list
            vm.tableShow.listCount = res.data.count
          } else {
            vm.$Message.error(res.msg)
          }
        })
      },
      // 上传部分
      handleImgFormatError (file) {
        this.$Notice.warning({
          title: '文件类型不合法',
          desc: file.name + '的文件类型不正确，请上传jpg或者png图片。'
        })
      },
      handleImgRemove () {
        this.formItem.headimg = ''
      },
      handleImgSuccess (response) {
        if (response.uploaded === 1) {
          this.$Message.success('上传成功!')
          this.formItem.headimg = response.url
          this.formItem.headimgid = response.headimgid
        } else {
          this.$Message.error(response.error.message)
        }
      },
      handleImgMaxSize (file) {
        this.$Notice.warning({
          title: '文件大小不合法',
          desc: file.name + '太大啦! 请上传小于5M的文件。'
        })
      },
      // 栏目类型转文字
      menuType (e) {
        let data = JSON.parse(localStorage.getItem('cmsMenu'))
        for (let v of data) {
          if (e === v.id) {
            return v.showName
          }
        }
      },
      // 显示图片空间列表
      showFilestList () {
        this.$refs.filestList.showFilestList()
      },
      // 获取子组件图片空间列表传来的imgUrl
      childImgUrl (imgData) {
        this.formItem.headimg = imgData.url
        this.formItem.headimgid = imgData.id
      },
      // 图片预览
      imgPreview (e) {
        this.modelImg = e.target.src
        this.imgModel = true
      },
      // 显示tag列表
      showTagstList () {
        this.$refs.tagstList.showTagstList()
      },
      // 获取子组件tag列表传来的tag
      childTag (data) {
        let tagName = data.name
        if(tagName){
          if(this.tagName.length > 0) {
            let fage = false
            for(let v of this.tagName){
              if(v !== tagName) {
                fage = false
              } else {
                fage = true
                break
              }
            }
            if(fage){
              this.$Message.warning('当前TAG标签已经存在！')
            } else {
              this.tagName.push(tagName)
            }
          } else {
            this.tagName.push(tagName)
          }
        }
      },
      isNull (e) {
        if (e === '' || e === undefined || e === 'undefined' || e === null || e === 'null' )
          return '--'
        else
          return e
      }
    },
    filters:{
      // 显示时间格式化
      timeType (e) {
        let moment = require('moment')
        let time = moment(e).format('YYYY-MM-DD HH:mm:ss')
        return time
      }
    }
  }
</script>
